//
//  ShareUsVC.m
//  hnGovernment
//
//  Created by 安仔 on 17/3/6.
//  Copyright © 2017年 安仔. All rights reserved.
//

#import "ShareUsVC.h"
#import "PublicServerCell.h"

@interface ShareUsVC ()<UICollectionViewDelegate, UICollectionViewDataSource>

@property (nonatomic, strong) UICollectionView *collectView;
//数据源
@property(nonatomic, strong) NSArray *collectDataArray;

@end

@implementation ShareUsVC

- (void)viewDidLoad {
    [super viewDidLoad];

    self.view.backgroundColor = RGB(243, 243, 243);
    self.title = NSLocalString(@"分享我们");
    
    [self createShareUsView];
    [self setUpData];
    [self initCollectionView];

}

- (void)createShareUsView {

    UIImageView *signImg = [[UIImageView alloc] init];
    signImg.clipsToBounds = YES;
    signImg.image = [UIImage imageNamed:@"河南政务logo"];
    signImg.backgroundColor = [UIColor clearColor];
    [self.view addSubview:signImg];
    [signImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.view.mas_centerX);
        make.top.mas_equalTo(120 * m6Scale);
        make.size.mas_equalTo(CGSizeMake(300 * m6Scale, 80 * m6Scale));
    }];
    
    
    UIImageView *codeImg = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"二维码"]];
    codeImg.clipsToBounds = YES;
    [self.view addSubview:codeImg];
    [codeImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.view.mas_centerX);
        make.top.mas_equalTo(290 * m6Scale);
        make.size.mas_equalTo(CGSizeMake(400 * m6Scale, 400 * m6Scale));
    }];
    
    UILabel *midLab = [[UILabel alloc] init];
    midLab.text = NSLocalString(@"分享我们");
    midLab.font = [UIFont systemFontOfSize:32 * m6Scale];
    midLab.textColor = RGB(103, 103, 103);
    midLab.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:midLab];
    [midLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.view.mas_centerX);
        make.top.mas_equalTo(874 * m6Scale);
        make.size.mas_equalTo(CGSizeMake(140 * m6Scale, 45 * m6Scale));
    }];
    
    UIView *letfLine = [[UIView alloc] initWithFrame:CGRectMake(60 * m6Scale, 896 * m6Scale, 220 * m6Scale, 2 * m6Scale)];
    letfLine.backgroundColor = RGB(222, 222, 222);
    [self.view addSubview:letfLine];
    
    UIView *rightLine = [[UIView alloc] initWithFrame:CGRectMake(472 * m6Scale, 896 * m6Scale, 220 * m6Scale, 2 * m6Scale)];
    rightLine.backgroundColor = RGB(222, 222, 222);
    [self.view addSubview:rightLine];
    

}

//初始化数据
- (void)setUpData {
    NSDictionary *dic1 = @{@"image":@"分享微信好友",
                           @"title":NSLocalString(@"微信好友")};
    NSDictionary *dic2 = @{@"image":@"分享朋友圈",
                           @"title":NSLocalString(@"朋友圈")};
    NSDictionary *dic3 = @{@"image":@"分享微博",
                           @"title":NSLocalString(@"新浪微博")};
    NSDictionary *dic4 = @{@"image":@"分享QQ",
                           @"title":NSLocalString(@"QQ")};
    
    self.collectDataArray = @[dic1, dic2, dic3, dic4];
}



//创建承载微应用的collectionView
- (void)initCollectionView {
    
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    layout.minimumInteritemSpacing = 0;
    layout.minimumLineSpacing = 0;
    layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    
    self.collectView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 960 * m6Scale, KScreenWidth, 160 * m6Scale) collectionViewLayout:layout];
    self.collectView.delegate = self;
    self.collectView.dataSource = self;
    self.collectView.showsVerticalScrollIndicator = NO;
    self.collectView.showsHorizontalScrollIndicator = NO;
    self.collectView.backgroundColor = RGB(243, 243, 243);
    
    //注册 colllectionCell
    [self.collectView registerClass:[PublicServerCell class] forCellWithReuseIdentifier:@"PublicServerCell"];
    [self.view addSubview:self.collectView];
    
}

#pragma mark- UICollectionViewDataSource
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return self.collectDataArray.count;
}

- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    PublicServerCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"PublicServerCell" forIndexPath:indexPath];
    cell.backgroundColor = RGB(243, 243, 243);
    
    [cell.signImg mas_updateConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(cell.mas_centerX);
        make.top.mas_equalTo(0);
        make.size.mas_equalTo(CGSizeMake(100 * m6Scale, 100 * m6Scale));
    }];

    NSDictionary *dicData = self.collectDataArray[indexPath.row];
    cell.signImg.image = [UIImage imageNamed:dicData[@"image"]];

    cell.titleLab.text = dicData[@"title"];
    cell.titleLab.textColor = RGB(103, 103, 103);
    cell.titleLab.font = [UIFont systemFontOfSize:28 * m6Scale];

    return cell;
}

#pragma mark- collectionView delegate
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    [collectionView deselectItemAtIndexPath:indexPath animated:YES];
    
    NSLog(@"点击了%ld个",indexPath.row);
    
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    return CGSizeMake(KScreenWidth / 4, self.collectView.bounds.size.height);
}

- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
    return UIEdgeInsetsMake(0.0, 0.0, 0.0, 0.0);
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
